package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author 喵喵喵
 * Date 2025/6/7 8:54
 */
@Api(tags="菜品套餐管理")
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @ApiOperation("套餐的分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageSetmeal(SetmealPageQueryDTO dto) {
        PageResult pageResult = setmealService.pageSetmeal(dto);
        return Result.success(pageResult);
    }
    @CacheEvict(cacheNames = "userSetMealCache",key = "#dto.getCategoryId()")
    @ApiOperation("套餐的新增")
    @PostMapping
    public Result addSetmeal(@RequestBody SetmealDTO dto) {
        setmealService.addSetmeal(dto);
        return Result.success();
    }

    @ApiOperation("根据id查询套餐信息")
    @GetMapping("/{id}")
    public Result<SetmealVO> getSetmealById(@PathVariable Long id) {
        SetmealVO setmealVO=setmealService.getSetmealById(id);
        return Result.success(setmealVO);
    }
    @CacheEvict(cacheNames = "userSetMealCache",key = "#dto.getCategoryId()")
    @ApiOperation("修改套餐信息")
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO dto) {
        setmealService.updateSetmeal(dto);
        return Result.success();
    }
    @CacheEvict(cacheNames = "userSetMealCache",key = "#dto.getCategoryId()")
    @ApiOperation("启用禁用套餐状态")
    @PostMapping("/status/{status}")
    public Result StartORStopStatus(@PathVariable Integer status, Integer id) {
        setmealService.StartORStopStatus(status, id);
        return Result.success();
    }
    @CacheEvict(cacheNames = "userSetMealCache",allEntries = true)
    @ApiOperation("套餐的批量删除")
    @DeleteMapping
    public Result deleteDishByIds(@RequestParam List<Long> ids) {
        setmealService.deleteSetmealByIds(ids);
        return Result.success();

    }

}
